package com.ellecity06.cwhiskymall.adapter

import android.graphics.Paint
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.text.buildSpannedString
import androidx.core.text.color
import androidx.core.text.scale
import com.ellecity06.common.base.BaseAdapter
import com.ellecity06.common.ktx.load
import com.ellecity06.cwhiskymall.bean.response.GoodResponse
import com.ellecity06.cwhiskymall.databinding.ItemSearchGoodBinding
import com.ellecity06.cwhiskymall.storage.UserStorage

/**
 * @author ellecity06
 * @time 2024/11/2 14:58
 * @des
 */
class SearchGoodAdapter : BaseAdapter<GoodResponse, ItemSearchGoodBinding>() {
    override fun inflateBinding(
        layoutInflater: LayoutInflater,
        parent: ViewGroup,
        viewType: Int
    ): ItemSearchGoodBinding {
        return ItemSearchGoodBinding.inflate(layoutInflater, parent, false)
    }

    override fun convert(binding: ItemSearchGoodBinding, position: Int, item: GoodResponse) {
        binding.ivGood.load(context,item.mainImage, radius = 10F)
        binding.tvContribution.visibility = UserStorage.upVisible()
        binding.tvGoodName.text = item.spuName
        binding.tvContribution.text = "赠送${item.contribution}贡献金"
        binding.tvOrgPrice.text = "原价： ${item.marketPrice}"
        binding.tvOrgPrice.paint.flags = Paint. STRIKE_THRU_TEXT_FLAG
        binding.tvOrgPrice.paint.isAntiAlias = true
        binding.tvStock.text = "库存： ${item.spuStock}"
        binding.tvGo.text = buildSpannedString {
          scale(0.8F){
              append("￥")
          }
            append("${item.salesPrice}")
        }
    }
}